package animator.phantom.renderer;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.io.*;
import java.awt.image.*;
import javax.swing.ImageIcon;
import animator.phantom.gui.*;

public class MovieSource extends SequencePlaybackSource
{
	private static ImageIcon movieicon = GUIResources.getIcon( GUIResources.movieicon );
	private File framesDir;

	public MovieSource(){}

	public MovieSource( File framesDir, File movieClip )
	{
		type = MOVIE_FILE;
		file2 = movieClip;
		this.framesDir = framesDir;
	}

	public void setData(File framesDir, File movieClip )
	{
		file2 = movieClip;
		this.framesDir = framesDir;
	}

	public void loadInit()
	{
		framesDir = new File( file.getParent() );
		initMovieSource();
	}

	public void initMovieSource()
	{
		File firstFrame = getFirstFrameFile( framesDir );
		init( firstFrame );
		framesDir = null;
	}

	private File getFirstFrameFile( File framesDir )
	{
		if( framesDir == null )
			return null;

		File[] files = framesDir.listFiles();
		if( files == null )
			return null;

		File first = null;
		int smallest = 1000000000;
		for( int i = 0; i < files.length; i++ )
		{
			int current = Integer.parseInt( getNumpart( files[ i ] ) );
			if( current < smallest )
			{
				first =  files[ i ];
				smallest = current;
			}
		}
		return first;
	}

	public File getFramesDir(){ return framesDir; }

	//--- Override
	public String getName(){ return file2.getName(); }
	public void loadData(){}
	public boolean dataInMemory(){ return false; }
	public void clearData(){}//--- not cached
	public void cacheOrClearData(){}//--- not cached
	public BufferedImage getBufferedImage(){ return null; }
	public ImageIcon getFileTypeIcon(){ return movieicon; }

}//end class
